#!/bin/sh
# main.tcl \
exec tclsh8.6 "$0" ${1+"$@"}

##################################################################################################################################
#
# Copyright (C) 2008-2013 Mind System Connection. Lda. Part of Daidze Software, created by Siqsuruq. All other rights reserved.
#
# Mind System Connection Webpage: www.msysc.org
# Daidze Software Page: www.daidze.com www.daidze.org
# E-mail: admin@msysc.org, siqsuruq@gmail.com
#
##################################################################################################################################
set lib_dic [dict create gen_lib [file join lib] win_lib [file join lib lib_windows] linix_lib [file join lib lib_linux] mac_lib [file join lib lib_mac] andro_lib [file join lib lib_android] common_lib [file join lib lib_common]]
foreach key [dict keys $lib_dic] {
	lappend ::auto_path [file join [pwd] [dict get $lib_dic $key]]
}




#External packages required by Daidze Software, most of them located in lib directory
##################################################################################################################################
# General Daidze 
##################################################################################################################################
package require Tk
package require pdf4tcl
package require msgcat
package require audit::audit
package require TclOO
package require md5
package require tooltip
package require tdom
package require csv
package require smtp
package require mime
package require tls
package require help
package require snit
package require textutil
package require fileutil
package require fileutil::magic::mimetype
package require sqlite3
package require struct::list
package require -exact tablelist_tile 5.11
package require Thread
package require ftp
package require widget::calendar
package require vfs::ftp
package require vfs
package require img::jpeg
package require img::png

##################################################################################################################################
# Pro Version Daidze 
##################################################################################################################################
# package require Pgtcl
package require pgintcl

##################################################################################################################################
# Old Version Daidze - only for comaptability (to delete)
##################################################################################################################################
# package require inifile 0.2.5
# package require pixane

##################################################################################################################################
# Platform specific packages
##################################################################################################################################
if {$tcl_platform(platform) eq "windows"} {
	#package require gdi
	#package require printer
	package require twapi
	package require cawt
	package require registry
}


# Include Source Files from incl directory and xml_wrapper class file

set files [glob [file join incl *]]
foreach f $files {
	source $f
}



# Read configuration database
read_config_db [file join conf daidze]
log_init


# Load Translations
msgcat::mclocale $language
msgcat::mcload [file join [file dirname [info script]] lang]

# Configure themes and styles
set_daidze_theme
source [file join $theme_dir daidze_classic.tcl]
install_fonts

# Create database handler
set db [my_sqlitedb new ./data/daidze_data.sdb]


set daidze_users::username ""
set daidze_users::groups ""

if {$daidze_users::username == ""} {
	login
} else {
	login
}



toplevel .splash

	wm overrideredirect .splash 1 ;# Make sure there is no title etc.
	set screenwidth  [winfo screenwidth  .]
	set screenheight [winfo screenheight .]

	set width 1600
	set height 1200

	wm minsize .splash $width $height  ;# Make sure it has the right size
	wm maxsize .splash $width $height

	set xsplash      [expr {($screenwidth  - $width)  / 2}]
	set ysplash      [expr {($screenheight - $height) / 2}]

	wm geometry      .splash +$xsplash+$ysplash
	label .splash.msg -image [image create photo -file [file join $img_dir splash_img6.png]]
	grid  .splash.msg             ;# Make it visible

	after 3000 {
		destroy .splash
	}

# Enable GUI debug window
if {$debug == "true"} {
	source debuggy.tcl
}